<?php

namespace App\Http\Controllers;

use App\Http\Resources\ContactResource;
use App\Models\Contact;
use Illuminate\Http\Request;

class ContactRestController extends Controller
{
    public function getAllContacts(){
//        $contacts = Contact::all();
//        $contact_resource = [];
//        foreach($contacts as $c){
//            $contact["id"] = $c->id;
//            $contact["fullname"] = "$c->first_name $c->last_name";
//            $contact["title"] = $c->title;
//            $records = [];
//            foreach($c->contact_records as $cr){
//                $record['method'] = $cr->method->name;
//                $record['record'] = $cr->record;
//                $records[] = $record;
//            }
//            $groups = [];
//            foreach($c->groups as $g){
//                $group["id"] = $g->id;
//                $group['name'] = $g->name;
//                $groups[] = $group;
//            }
//            $contact["contact_by"] = $records;
//            $contact['groups'] = $groups;
//            $contact_resource[] = $contact;
//
//        }
        return response()->json([
            'msg'=>'success',
            'data'=>ContactResource::collection(Contact::all())
        ]);
    }
}
